package cn.hs.controller;/**
 * @author Jovan Hou 2024/10/28
 **/

import cn.hs.entity.Mynotice;
import cn.hs.entity.Mytest;
import cn.hs.mapper.MytestMapper;
import cn.hs.service.MyTestService;
import cn.hs.service.MynoticeService;
import cn.hs.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MyTestController
 * @Description TODO
 * @Author CnYuu
 * @Date 2024年10月28日 17:27
 * @Version 1.0
 */
@RestController
@RequestMapping("/mytest")
public class MyTestController
{
    @Autowired
    private MyTestService service;
//    @GetMapping("/find")
//    public Object find(
//            @RequestParam(defaultValue = "1") Integer pageNum,
//            @RequestParam(defaultValue = "10") Integer pageSize,
//            Mynotice mynotice
//    ){
//        PageInfo pageInfo = mynoticeService.findAll(pageNum, pageSize,mynotice);
//        return  Result.success(pageInfo);
//    }
    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam
            Integer id){

        PageInfo pageInfo = service.findByUserId(pageNum, pageSize,id);
        return  Result.success(pageInfo);
    }

    @PostMapping("/insert")
    public Result insert( @RequestBody Mytest mytest){
        int add = service.insert(mytest);
        if (add == 1) {
            return Result.success(add);
        }
        return Result.error("添加失败");
    }

    @PostMapping("/delete")
    public Result insert( @RequestBody Integer id){
        int add = service.delete(id);
        if (add == 1) {
            return Result.success(add);
        }
        return Result.error("删除失败");
    }

    @PostMapping("/deleteByAllId")
   public Result deleteById(@RequestBody Mytest mytest){

        int i = service.deleteByAllId(mytest);
        return Result.success(i);

    }


}
